import { configureStore } from '@reduxjs/toolkit';
import {
  persistStore,
  persistReducer,
  FLUSH,
  REHYDRATE,
  PAUSE,
  PERSIST,
  PURGE,
  REGISTER,
} from 'redux-persist';
import storage from 'redux-persist/lib/storage';
import homeReducer from './home';
const persistHomeConfig = {
  key: 'home',
  version: 1,
  whitelist: ['count'], // 指定哪些reducer需要被持久化
  storage,
};
const persistedHomeReducer = persistReducer(persistHomeConfig, homeReducer);
const store = configureStore({
  reducer: {
    home: persistedHomeReducer,
  },
  middleware: (getDefaultMiddleware) =>
    getDefaultMiddleware({
      serializableCheck: {
        ignoredActions: [FLUSH, REHYDRATE, PAUSE, PERSIST, PURGE, REGISTER],
      },
    }),
});

export type AppDispatch = typeof store.dispatch;
export type RootState = ReturnType<typeof store.getState>;
export const persistor = persistStore(store);
export default store;
